package tech.threekilogram.contenttransitiontest;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.PagerSnapHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SnapHelper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * @author liujin
 */
public class ShareElementPagerActivity extends AppCompatActivity {

      private RecyclerView mPager;

      public static void start ( Context context, View view, String transitionName ) {

            Intent starter = new Intent( context, ShareElementPagerActivity.class );
            context.startActivity(
                starter,
                ActivityOptionsCompat
                    .makeSceneTransitionAnimation( (Activity) context, view, transitionName )
                    .toBundle()
            );
      }

      public static void start ( Context context ) {

            Intent starter = new Intent( context, ShareElementPagerActivity.class );
            context.startActivity( starter );
      }

      @Override
      protected void onCreate ( Bundle savedInstanceState ) {

            super.onCreate( savedInstanceState );
            setContentView( R.layout.activity_share_element_pager );
            initView();
      }

      private void initView ( ) {

            mPager = findViewById( R.id.pager );
            LinearLayoutManager layoutManager = new LinearLayoutManager( this );
            layoutManager.setOrientation( RecyclerView.HORIZONTAL );
            mPager.setLayoutManager( layoutManager );
            mPager.setAdapter( new ShareAdapter() );
            SnapHelper snapHelper = new PagerSnapHelper();
            snapHelper.attachToRecyclerView( mPager );
      }

      private class ShareAdapter extends RecyclerView.Adapter<ViewHolder> {

            @NonNull
            @Override
            public ViewHolder onCreateViewHolder (
                @NonNull ViewGroup parent, int viewType ) {

                  View view = LayoutInflater.from( parent.getContext() )
                                            .inflate( R.layout.item_share_pager, parent, false );
                  return new ViewHolder( view );
            }

            @Override
            public void onBindViewHolder (
                @NonNull ViewHolder holder, int position ) {

            }

            @Override
            public int getItemCount ( ) {

                  return 5;
            }
      }

      private class ViewHolder extends RecyclerView.ViewHolder {

            public ViewHolder ( View itemView ) {

                  super( itemView );
            }

            void onBind ( int position ) {

            }
      }
}
